using System.Collections;
using UnityEngine;

public class ShadowCam : MonoBehaviour
{
	public GameObject shadowPlane;

	public Shader shadowShader;

	private RenderTexture rt;

	private int captureWidth = 2048;

	private int captureHeight = 2048;

	public static bool update;

	private void Start()
	{
		base.gameObject.GetComponent<Camera>().orthographicSize = shadowPlane.transform.localScale.x / 2f;
		base.gameObject.GetComponent<Camera>().enabled = false;
		rt = new RenderTexture(captureWidth, captureHeight, 24, RenderTextureFormat.ARGB32);
		rt.useMipMap = true;
		rt.antiAliasing = 1;
		rt.filterMode = FilterMode.Bilinear;
		rt.anisoLevel = 1;
		base.gameObject.GetComponent<Camera>().targetTexture = rt;
		RenderTexture.active = rt;
		shadowPlane.GetComponent<Renderer>().material.mainTexture = rt;
		shadowPlane.SetActive(false);
	}

	private void LateUpdate()
	{
		if (update || true)
		{
			StartCoroutine(UpdateShadowsAtEndOfFrame());
			update = false;
		}
	}

	private IEnumerator UpdateShadowsAtEndOfFrame()
	{
		yield return new WaitForEndOfFrame();
		UpdateShadows();
	}

	public void UpdateShadows()
	{
		base.gameObject.GetComponent<Camera>().RenderWithShader(shadowShader, "ColorCoding");
		shadowPlane.SetActive(true);
	}
}
